
function finishs() {

    let radios = localStorage.getItem("radios");
    radios = JSON.parse(radios);
    if (radios[0][0] != null)
        radios = radios;
    else {
        radios = [
            legal_point = [3, 3, 3, 3],
            pp_point = [3, 3, 3, 3, 3],
            hours_point = [3, 3, 3, 3],
            cr_point = [3, 3],
            pm_point = [3, 3, 3, 3, 3, 3],
            tt_point = [3, 3],
            rr_point = [3, 3, 3, 3, 3],
            hs_point = [3, 3, 3],
            covid_point = [3, 3, 3],
            er_point = [3, 3, 3],
            pb_point = [3, 3, 3, 3],
            ece_point = [3, 3, 3],
            erg_point = [3, 3, 3]
        ];
        window.location.href = "form_upload.html";
        return;
    }

    let notFilledId = null;

    for (let i = 0; i < 13; i++) {
        for (let l = 0; l < radios[i].length; l++) {
            if (radios[i][l] == 3 || radios[i][l] == null) {
                notFilledId = i;
                break;
            }
        }
    }

    if (notFilledId != null) {
        alert("还有问题未填写答案！请填写!2s后跳转。。。");
        setTimeout(function () {
            if (notFilledId == 0) {
                notFilledId = null;
                window.location.href = "form_wizards.html";
                return;
            } else if (notFilledId == 1) {
                notFilledId = null;
                window.location.href = "form_wizards.html";
                return;
            } else if (notFilledId == 2) {
                notFilledId = null;
                window.location.href = "form_upload.html";
                return;
            } else if (notFilledId == 3) {
                notFilledId = null;
                window.location.href = "form_upload.html";
                return;
            } else if (notFilledId == 4) {
                notFilledId = null;
                window.location.href = "chartjs.html";
                return;
            } else if (notFilledId == 5) {
                notFilledId = null;
                window.location.href = "chartjs.html";
                return;
            } else if (notFilledId == 6) {
                notFilledId = null;
                window.location.href = "chartjs2.html";
                return;
            } else if (notFilledId == 7) {
                notFilledId = null;
                window.location.href = "chartjs2.html";
                return;
            } else if (notFilledId == 8) {
                notFilledId = null;
                window.location.href = "chartjs2.html";
                return;
            } else if (notFilledId == 9) {
                notFilledId = null;
                window.location.href = "fixed_sidebar.html";
                return;
            } else if (notFilledId == 10) {
                notFilledId = null;
                window.location.href = "fixed_sidebar.html";
                return;
            } else if (notFilledId == 11) {
                notFilledId = null;
                window.location.href = "fixed_footer.html";
                return;
            } else if (notFilledId == 12) {
                notFilledId = null;
                window.location.href = "fixed_footer.html";
                return;
            }
        }, 2000);
    }

    let data = {
        account: '5656',
        legal_point: 0,
        pp_point: 0,
        hours_point: 0,
        cr_point: 0,
        pm_point: 0,
        tt_point: 0,
        rr_point: 0,
        hs_point: 0,
        covid_point: 0,
        er_point: 0,
        pb_point: 0,
        ece_point: 0,
        erg_point: 0
    }

    let sum = 0;
    for (let i = 0; i < 13; i++) {
        sum = 0;
        for (let l = 0; l < radios[i].length; l++) {
            if (radios[i][l] != null && radios[i][l] == 0)
                sum = sum + 1;
            else if (radios[i][l] != null && radios[i][l] == 1)
                sum = sum + 10;
            else if (radios[i][l] != null && radios[i][l] == 2)
                sum = sum + 100;
        }

        if (i == 0)
            data.legal_point = sum * 1;
        else if (i == 1)
            data.pp_point = sum * 1;
        else if (i == 2)
            data.hours_point = sum * 1;
        else if (i == 3)
            data.cr_point = sum * 1;
        else if (i == 4)
            data.pm_point = sum * 1;
        else if (i == 5)
            data.tt_point = sum * 1;
        else if (i == 6)
            data.rr_point = sum * 1;
        else if (i == 7)
            data.hs_point = sum * 1;
        else if (i == 8)
            data.covid_point = sum * 1;
        else if (i == 9)
            data.er_point = sum * 1;
        else if (i == 10)
            data.pb_point = sum * 1;
        else if (i == 11)
            data.ece_point = sum * 1;
        else if (i == 12)
            data.erg_point = sum * 1;

    }

    data.account = getUser().account;
    let re = rqeuest("/user/submit", 'POST', data)
    if (re.code == 0) {
        alert(re.message);
        location.reload();
    }else{
        alert(re.message);
    }
}
function nexts(x, y, z, q, w, t) {
    let radios = localStorage.getItem("radios");
    radios = JSON.parse(radios);
    if (radios != null && radios[0] != null && radios[0][0] != null)
        radios = radios;
    else
        radios = [
            legal_point = [3, 3, 3, 3],
            pp_point = [3, 3, 3, 3, 3],
            hours_point = [3, 3, 3, 3],
            cr_point = [3, 3],
            pm_point = [3, 3, 3, 3, 3, 3],
            tt_point = [3, 3],
            rr_point = [3, 3, 3, 3, 3],
            hs_point = [3, 3, 3],
            covid_point = [3, 3, 3],
            er_point = [3, 3, 3],
            pb_point = [3, 3, 3, 3],
            ece_point = [3, 3, 3],
            erg_point = [3, 3, 3]
        ];

    for (let i = 0; i < x; i++) {
        let r = document.getElementsByName((i + 1).toString());
        let ch = null;
        for (let j = 0; j < 3; j++) {
            if (r[j].checked) {
                ch = j;
                break;
            }
        }

        if (w == null && t == null && i < y)
            radios[z][i] = ch == null ? 3 : ch
        if (w == null && t == null && i >= y)
            radios[q][i - y] = ch == null ? 3 : ch

        if (w != null && t != null && i < y)
            radios[z][i] = ch == null ? 3 : ch
        else if (w != null && t != null && i > (y - 1) && i < (y + t))
            radios[q][i - y] = ch == null ? 3 : ch
        else if (w != null && t != null)
            radios[w][i - (y + t)] = ch == null ? 3 : ch

    }
    localStorage.setItem("radios", JSON.stringify(radios));
}

function initialize(x, y, z, q, w, t) {
    let radios = localStorage.getItem("radios");
    if (radios != null) {
        radios = JSON.parse(radios);
        console.log(radios);
        for (let i = 0; i < x; i++) {
            if (w == null && t == null && i < y && radios[z][i] != null && radios[z][i] != 3)
                document.getElementsByName((i + 1).toString())[radios[z][i]].checked = true;
            if (w == null && t == null && i >= y && radios[q][i - y] != null && radios[q][i - y] != 3)
                document.getElementsByName((i + 1).toString())[radios[q][i - y]].checked = true;

            if (w != null && t != null && i < y && radios[z][i] != null && radios[z][i] != 3)
                document.getElementsByName((i + 1).toString())[radios[z][i]].checked = true;
            else if (w != null && t != null && i > (y - 1) && i < (y + t) && radios[q][i - y] != null && radios[q][i - y] != 3)
                document.getElementsByName((i + 1).toString())[radios[q][i - y]].checked = true;
            else if (w != null && t != null && radios[w][i - (y + t)] != null && radios[w][i - (y + t)] != 3)
                document.getElementsByName((i + 1).toString())[radios[w][i - (y + t)]].checked = true;
        }
    }
}

function rqeuest(url, post, dataobj) {
    let user = localStorage.getItem("token");
    user = JSON.parse(user);
    let host = "http://localhost:8080";
    url = host + url;
    var data1 = null;
    $.ajax({
        url: url,
        type: post,
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(dataobj),
        Caches: false,
        async: false,
        dataType: "json",
        headers: {
            'loginuser':user
        },
        success: function (data) {
            data1 = data;
        },
        error: function (data) {
            return null;
        }
    });
    return data1;
}

function getUser() {
    let user = localStorage.getItem("user");
    user = JSON.parse(user);
    if (user == null) {
        alert("token以过期或用户未登录，请重新登陆！");
        window.location.href = "login.html";
    } else {
        document.getElementById('userNamesOne').innerHTML = user.account ? user.account : 'John Doe';
        document.getElementById('userNamesTwo').innerHTML = user.account ? user.account : 'John Doe';
        return user;
    }

}
